import { exportWE, fakeSIssueAnswerTatisticsData, exportx, exportWD, detailCategoryList, detailDetailList } from '@/services/datastatistics';

export default {
  namespace: 'AnswerDetailStatis',

  state: {
    list: [],
    total: '',
  },
  effects: {
    *detailDetailList({ payload, callback }, { call, put }) {
      const response = yield call(detailDetailList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *detailCategoryList({ payload, callback }, { call, put }) {
      const response = yield call(detailCategoryList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(fakeSIssueAnswerTatisticsData, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *fetchb({ payload, callback }, { call, put }) {
      const response = yield call(exportx, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *exportWD({ payload, callback }, { call, put }) {
      const response = yield call(exportWD, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *exportWE({ payload, callback }, { call, put }) {
      const response = yield call(exportWE, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list: [],
        total: '',
      };
    },
  },
};
